﻿using System;
using System.Collections.Generic;
using System.Text;

namespace gTray
{
    public class Feed
    {
        public string Title { get; set; }
        public int Count { get; set; }
        public Uri Link { get; set; }
        public DateTime Modified { get; set; }
        public List<FeedEntry> Entries { get; set; }
        public int UpdateCount { get; private set; }
        public List<FeedEntry> NewEntries { get; private set; }

        public int MaxUnreadCount
        {
            get
            {
                if (this.UpdateCount >= 1)
                    return Math.Max(this.NewEntries.Count, this.Count);
                else
                    return this.NewEntries.Count;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Feed"/> class.
        /// </summary>
        public Feed()
        {
            this.Entries = new List<FeedEntry>();
            this.NewEntries = new List<FeedEntry>();
            this.UpdateCount = 0;
        }

        /// <summary>
        /// Adds the new entries.
        /// </summary>
        /// <param name="newEntries">The new entries.</param>
        public void AddNewEntries(List<FeedEntry> UpdatedEntries)
        {
            this.UpdateCount++;
            this.NewEntries.Clear();

            foreach (FeedEntry entry in UpdatedEntries)
            {
                if (!this.Entries.Contains(entry))
                {
                    this.NewEntries.Add(entry);
                }
            }

            this.Entries = UpdatedEntries;
        }
    }
}
